<?php namespace Home\Controller; 
//个人中心控制器
use \Home\Model\OrderList;
use \Home\Model\User;
class OrderController extends CommonController{
    private $Model;
//  自定义构造函数
    public function __auto(){
        //引Model文件
        $this->Model = new \Home\Model\User;
    } 
    
//  首页
    public function index(){
    	if(isset($_SESSION['user'])){
    		$orderListModel = new OrderList();
			$orderListData = $orderListModel
							->join('orders as o','order_list.orders_oid','=','o.oid')
							->join('goods','order_list.goods_aid','=','aid')
							->orderBy('status')
							->get();
	//		p($orderListData);
			View::with('orderListData',$orderListData);
    	}else{
    		go(U('Login/index'));
    	}
        View::make();
    }

//  编辑
    public function edit(){
        View::make();
    }
//	修改密码
	public function changePassWord(){

		if(IS_POST){
			if(!$this->Model->store()) View::error($this->Model->getError());
			View::success("修改成功");
		}
		
	    View::make();
	}
	//个人信息
	public function information(){
//		2.修改
		$userModel = new User();
		$uid = $_SESSION['user']['uid'];
		if(IS_POST){
			$data=[
				'account'=>Q('post.account'),
				'sex'=>Q('post.sex'),
				'birthday'=>implode('-', Q('post.birthday')),
				'realname'=>Q('post.realname'),
				'number'=>Q('post.number'),
				'identity'=>Q('post.identity')
			];
			$userModel->where("uid={$uid}")->update($data);
		}
		//1.获得旧数据
		$userData = $userModel->where("uid={$uid}")->find();
		$userData['birthday']=explode('-', $userData['birthday']);
		View::with('userData',$userData);
	    View::make();
	}
	
	//收获地址
	public function address(){
	    View::make();
	}
	
}